package mao.exaimnation.ziguang;

import java.util.Scanner;

/**
 * @author Totoro
 * @date 2020/9/10
 * @explain:
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            int max = scanner.nextInt();
            long res = 0;
            int tmp = 0;
            for (int i = 100; i <= max; i++) {
                tmp = i;
                if (tmp % 10 == 7) continue;
                tmp/=10;
                if (tmp % 10 == 5) continue;
                tmp/=10;
                if (tmp == 3) continue;
                res+=i;
            }
            System.out.println(res);
        }
    }
}
